import 'package:flutter/material.dart';
import 'package:zhuhu_demo/domain/web_page/web_page.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../domain/home/home_page.dart';
import '../service/route_names.dart';

final Map<String, Widget Function(BuildContext)> routes = {
  RouteNames.shared.home: (context) => const HomePage(),
  RouteNames.shared.web: (context, {Map<String, String>? arguments}) =>
      WebPage(arguments: arguments)
};

class ZhuhuApp extends StatelessWidget {
  const ZhuhuApp({super.key});

  Widget get materialApp {
    return MaterialApp(
        initialRoute: '/home',
        onGenerateRoute: (settings) {
          Function? builder = routes[settings.name];
          var arguments = settings.arguments;
          if (builder == null) {
            return null;
          }
          if (arguments == null) {
            return MaterialPageRoute(builder: (context) => builder(context));
          }
          return MaterialPageRoute(
              builder: (context) => builder(context, arguments: arguments));
        });
  }

  @override
  Widget build(BuildContext context) {
    return ProviderScope(child: materialApp);
  }
}
